package com.lyl.momanapp.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.google.gson.Gson;
import com.lyl.momanapp.R;
import com.lyl.momanapp.adapter.ShopCar;
import com.lyl.momanapp.bean.ShopCarBean;
import com.lyl.momanapp.bean.URL;
import com.lyl.momanapp.util.utlis.MyUtils;
import com.lyl.momanapp.util.view.MyBaseActivity;

import java.util.ArrayList;
import java.util.HashMap;

import static com.lyl.momanapp.bean.URL.Userlogin;

/**
 * 名字 梁亚龙
 * 时间 2017/9/28.
 * QQ邮箱 503934353@qq.com
 * 购物车
 */

public class ShopCarActivity extends MyBaseActivity {
    private ImageView mFanhui;
    private ImageView mZhuye;
    private ListView mLV;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case URL.ID_shoppingList: {
                    ShopCarBean shopCarBean = new Gson().fromJson(msg.obj.toString(), ShopCarBean.class);
                    ShopCar shopCar = new ShopCar(ShopCarActivity.this, (ArrayList<ShopCarBean.ResultBean.GoodsBean.VaildBean>) shopCarBean.getResult().getGoods().getVaild());
                    mLV.setAdapter(shopCar);
                }
                break;
            }
        }
    };

    @Override
    public void initUI() {
        setContentView(R.layout.activity_shop_car);
        mFanhui = ((ImageView) findViewById(R.id.fanhui));
        mZhuye = ((ImageView) findViewById(R.id.zhuye));
        mLV = ((ListView) findViewById(R.id.shop_car_lv));
    }

    @Override
    public void initData() {
        HashMap<String, String> map = new HashMap<>();
        map.put("user_id", Userlogin.getResult().getUser_id() + "");
        new MyUtils().xUtilsPost(URL.URLshoppingList, map, handler, URL.ID_shoppingList);
    }

    @Override
    public void addListeners() {
        mFanhui.setOnClickListener(this);
        mZhuye.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fanhui: {
                finish();
            }
            break;
            case R.id.zhuye: {

                startActivity(new Intent(ShopCarActivity.this, MainActivity.class));
                finish();
            }
            break;

        }
    }

}
